/*
** 2453.c
** 
** Made by (seakage2h)
** Login   <seakage2h@seakage2h-ubuntu>
** 
** Started on  Sun Sep 21 22:20:52 2008 seakage2h
** Last update Sun May 12 01:17:25 2002 Speed Blue
*/

/*
 * BIT OPERATIONS heavily used here
 */

/* #include "2453.h" */
#include <stdio.h>

int main()
{
     int target;
     int i,j;
     
     while(scanf("%d", &target)){
	  if (target == 0) break;
	  if (target & 1){	     /* the lowest bit is 0 */
	       for(i = 1; target & (1 << i); i++); /* find the lowest 0 */
	       target |= (1 << i);   /* set the first met 0 to 1 */
	       target &= ~(1 << (i - 1)); /* set the previous bit to 0 */
	  }				  /* FINISH: odd number */
	  else{
	       for(i = 1; !(target & (1 << i)); i++); /* find the lowest 1 */
	       for(j = i; target & (1 << j); j++);    /* find next 0 */
	       target += ((1 << i) + (1 << (j - i - 1)) - 1); /* magic */
	  }
	  printf("%d\n", target);
     }
     return 0;
}

		    
